<?php
// +----------------------------------------------------------------------
// | Powered By ThinkPHP 5.0.12
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.bojuwang.net All rights reserved.
// +----------------------------------------------------------------------
// | Date：2017-12
// +----------------------------------------------------------------------
// | Author: ZhengLuwei <512711380@qq.com>
// +----------------------------------------------------------------------

namespace app\bjwlmanager\controller;

use think\Controller;
use think\Db;
use think\Request;

class Index extends ManagerBasic
{
    public function index()
    {

        //订单
        $orderCount = Db::name('goods_order')->where('status',1)->count();
        $this->assign('orderCount',$orderCount);
        $todayOrderCount = Db::name('goods_order') ->whereTime('add_time', 'today')->where('status',1)->count();
        $this->assign('todayOrderCount',$todayOrderCount);
        $yesterdayOrderCount = Db::name('goods_order') ->whereTime('add_time', 'yesterday')->where('status',1)->count();
        $this->assign('yesterdayOrderCount',$yesterdayOrderCount);
        $weekOrderCount = Db::name('goods_order') ->whereTime('add_time', 'week')->where('status',1)->count();
        $this->assign('weekOrderCount',$weekOrderCount);
        $monthOrderCount = Db::name('goods_order') ->whereTime('add_time', 'month')->where('status',1)->count();
        $this->assign('monthOrderCount',$monthOrderCount);
        //提现
        $cashCount = Db::name('user_cash')->where('status',0)->count();
        $this->assign('cashCount',$cashCount);
        $todayCashCount = Db::name('user_cash') ->whereTime('add_time', 'today')->where('status',0)->count();
        $this->assign('todayCashCount',$todayCashCount);
        $yesterdayCashCount = Db::name('user_cash') ->whereTime('add_time', 'yesterday')->where('status',0)->count();
        $this->assign('yesterdayCashCount',$yesterdayCashCount);
        $weekCashCount = Db::name('user_cash') ->whereTime('add_time', 'week')->where('status',0)->count();
        $this->assign('weekCashCount',$weekCashCount);
        $monthCashCount = Db::name('user_cash') ->whereTime('add_time', 'month')->where('status',0)->count();
        $this->assign('monthCashCount',$monthCashCount);

        //用户
        $userCount = Db::name('user')->count();
        $this->assign('userCount',$userCount);
        $todayUserCount = Db::name('user') ->whereTime('add_time', 'today')->count();
        $this->assign('todayUserCount',$todayUserCount);
        $yesterdayUserCount = Db::name('user') ->whereTime('add_time', 'yesterday')->count();
        $this->assign('yesterdayUserCount',$yesterdayUserCount);
        $weekUserCount = Db::name('user') ->whereTime('add_time', 'week')->count();
        $this->assign('weekUserCount',$weekUserCount);
        $monthUserCount = Db::name('user') ->whereTime('add_time', 'month')->count();
        $this->assign('monthUserCount',$monthUserCount);
        //积分订单
        $integralCount = Db::name('integral_order')->where('status',0)->count();
        $this->assign('integralCount',$integralCount);
        $todayIntegralCount = Db::name('integral_order') ->whereTime('add_time', 'today')->where('status',0)->count();
        $this->assign('todayIntegralCount',$todayIntegralCount);
        $yesterdayIntegralCount = Db::name('integral_order') ->whereTime('add_time', 'yesterday')->where('status',0)->count();
        $this->assign('yesterdayIntegralCount',$yesterdayIntegralCount);
        $weekIntegralCount = Db::name('integral_order') ->whereTime('add_time', 'week')->where('status',0)->count();
        $this->assign('weekIntegralCount',$weekIntegralCount);
        $monthIntegralCount = Db::name('integral_order') ->whereTime('add_time', 'month')->where('status',0)->count();
        $this->assign('monthIntegralCount',$monthIntegralCount);
        return view();
    }

    public function getUserNextAgentData() {
        $data = Db::name('user_distribution')->alias('b')
            ->field('a.user_name,a.status,a.true_name,a.user_nickname,a.mobile,a.type,a.add_ip,a.add_time,b.*')
            ->join('user a','a.id=b.next_user_id')
            ->where('b.user_id',$userId)
            ->select();
            return $data;
    }
    function get_user_agent($userId)
    {
        $first = getUserNextAgentData($userId);
        if ($first)
        {
            $data['first'] = $first;
            $data['first_count'] = count($first);
            foreach ($first as $k1=>$v1)
            {
                $second = getUserNextAgentData($v1['next_user_id']);
                if ($second)
                {
                    $data['second'] = $second;
                    $data['second_count'] = count($second);
                    foreach ($second as $k2=>$v2)
                    {
                        $third = getUserNextAgentData($v2['next_user_id']);
                        if ($third)
                        {
                            $data['third'] = $third;
                            $data['third_count'] = count($third);
                        }
                    }
                }
            }
        }
        return $data;
    }

}